<!--阅卷管理-->
<!--题目管理-->
<template>
  <div>
    <a-card class="contentFullHeight" :bodyStyle="{padding : '10px 10px'}">
      <!--筛选、导入导出-->
      <a-card :bordered="true" class="searchBox" :bodyStyle="{padding : '10px 24px'}">
        <a-form layout="inline">
          <a-form-item label="是否已阅">
            <a-select v-model="searchParams.createBy" allowClear>
              <a-select-option value="">全部</a-select-option>
              <a-select-option value="1">已阅</a-select-option>
              <a-select-option value="2">待阅</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="试卷名称">
            <a-input style="width: 150px" v-model="searchParams.keywords"></a-input>
          </a-form-item>
          <a-form-item label="个人用户/环保局用户名称">
            <a-input style="width: 150px" v-model="searchParams.userName"></a-input>
          </a-form-item>
          <a-form-item label="企业名称">
            <a-input style="width: 150px" v-model="searchParams.companName"></a-input>
          </a-form-item>
          <a-form-item>
            <a-button type="primary" icon="search" @click="handleSearch">查询</a-button>
          </a-form-item>
          <!--<a-form-item>-->
            <!--<a-button type="primary" icon="download" @click="handleDownload" :loading="downloadLoading">导出</a-button>-->
          <!--</a-form-item>-->
        </a-form>
      </a-card>
      <!--列表-->
      <a-table
        :columns="columns"
        :dataSource="data"
        bordered
        size="small"
        :pagination="pagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <!--<template slot="userNumber" slot-scope="text,record">-->
        <!--{{text}}-->
        <!--</template>-->

        <!--<template slot="status" slot-scope="text,record">-->
        <!--{{text|status}}-->
        <!--</template>-->

        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="setDefaults(record)" href="javascript:;" v-if="record.isCheck==2">去阅卷</a>
            <a-divider type="vertical" v-if="record.isCheck==2"/>
            <a href="javascript:;" @click="showConfirm(record)">删除</a>
          </template>
        </span>
      </a-table>
      <!--阅卷弹窗-->
      <ReviewPopup :mdl="mdl" @handleSearch="handleSearch"></ReviewPopup>
    </a-card>
  </div>
</template>

<script>
import moment from 'moment'
import ReviewPopup from './form'
import {examRecordquery,examRecorddelete} from '@/api/examManage/questionBankManage'
export default {
  components: {
    ReviewPopup
  },
  data () {
    return {

      /*   -------搜索框-------- */
      searchParams: {
        keywords: '',
        createBy: '',
        companName: '',
        userName: ''
      },

      /*   -------分页-------- */
      pagination: this.$defaultSettings.pagination,

      /*   -------弹窗-------- */
      mdl: {
        visible: false,
        formData: {
          "id": '',//考试对应题目记录
          "aTime": '',
          "questionId": '', // 问题id
          "userTime": '',
          "questionType": 3, // 问题类型
          "answerReply": '', // 简答题答题记录
          "examRecordId": '', // 考试记录id
          "sign": '', // 标识
          "score": '', // 题目得分
          "examTitleID": '', // 考试id
          "isOK": "", // 是否正确
          "memberID": '', // 答题人员id
          "atime": '',
          "answer": '',
          passGrade: ''
        },
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 5
          }
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          }
        },
        formItemLayoutWithOutLabel: {
          wrapperCol: {
            xs: { span: 24, offset: 0 },
            sm: { span: 20, offset: 4 }
          }
        }
      },

      /*   -------表格-------- */
      loading: false,
      columns: [
        {
          title: '试卷名称',
          dataIndex: 'examName'
        },
        {
          title: '考试时间',
          dataIndex: 'BTime',
        },
        {
          title: '答题人名称',
          dataIndex: 'userName'
        },
        {
          title: '所属公司/个人',
          dataIndex: 'companName'
        },
        {
          title: '总分',
          dataIndex: 'tscroe'
        },
        {
          title: '得分',
          dataIndex: 'score',
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '150px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      data: [],

      // 下载
      downloadLoading: false
    }
  },
  inject: ['upShow'],
  filters: {

  },
  created () {
    this.getTableData()
  },
  computed: {

  },
  methods: {
    moment,
    onChange (dates, dateStrings) {
      // console.log('From: ', dates[0], ', to: ', dates[1]);
      this.searchParams.bgTm = dateStrings[0]
      this.searchParams.endTm = dateStrings[1]
    },
    handleTableChange (pagination, filters, sorter) {
      this.pagination = pagination
      let sortOrder = ''
      const sortField = sorter.field ? sorter.field : ''
      if (sorter.order) {
        sortOrder = sortOrder === 'ascend' ? 'asc' : 'desc'
      }
      this.getTableData(sortField, sortOrder)
    },

    getTableData (sortField, sortOrder) {
      this.loading = true
      const parameter = {
        pageSize: this.pagination.pageSize || 10,
        pageNumber: this.pagination.current || 1,
        "_search": true,
        "data": {
          isCheck:this.searchParams.createBy, // 1已阅 2未阅
          companName:this.searchParams.companName, //企业名称
          userName:this.searchParams.userName//答题人名称
        },
        "selected": "exam_name",//模糊搜索试卷
        "keywords": this.searchParams.keywords,//模糊搜索试卷名称
      }
      examRecordquery(parameter).then(res => {
        this.loading = false
        this.pagination.total = res.data.total
        this.data = res.data.records
      })
        .catch(err => {
          this.loading = false
        })
    },
    handleSearch () {
      this.mdl.visible = false
      this.pagination.current = 1
      this.getTableData()
    },

    setDefaults (row) {
      this.mdl.formData = {
        "id": row.id,//考试对应题目记录
        "aTime": '',
        "questionId": '', // 问题id
        "userTime": '',
        "questionType": 3, // 问题类型
        "answerReply": '', // 简答题答题记录
        "examRecordId": '', // 考试记录id
        "sign": '', // 标识
        "score": row.score, // 题目得分
        "examTitleID": '', // 考试id
        "isOK": "", // 是否正确
        eid: row.eid,
        "memberId": row.memberId, // 答题人员id
        "atime": '',
        "answer": '',
        passGrade: Number(row.passGrade)
      }
      this.mdl.visible = true
    },

//    删除
    handleDelete (row) {
        var params = {
            id: row.id,
          examinationInfoID: row.examinationInfoID
        }
      examRecorddelete(params).then(res => {
        if (res.code === 200) {
          this.upShow(1, res.msg || '删除成功')
          this.handleSearch()
        } else {
          this.upShow(2, res.msg)
        }
      }).catch(err => {
          this.upShow(2)
        })
    },
    showConfirm (val) {
        var that = this
      this.$confirm({
        title: '删除退款记录?',
        content: '确定删除用户' + val.userName + '的《'+val.examName+'》考试记录',
        onOk () {
          that.handleDelete(val)
        },
        onCancel () {}
      })
    },
  }
}
</script>
